package com.uroad.jilinpda.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.uroad.jilinpda.R;
import com.uroad.jilinpda.bleactivation.TopUpUtil;
import com.uroad.jilinpda.modle.OBUSystemInfoMDL;


/**
 * @创建者 wlw
 * @创建时间 2019/6/16 17:04
 * @描述
 */
public class OBUSystemInfoFragment extends Fragment {
    private View view;
//    @BindView(R.id.tvObuId)
    TextView tvObuId;
//    @BindView(R.id.tvObuNo)
    TextView tvObuNo;
//    @BindView(R.id.tvObuDefinition)
    TextView tvObuDefinition;
//    @BindView(R.id.tvObuType)
    TextView tvObuType;
//    @BindView(R.id.tvObuStartDate)
    TextView tvObuStartDate;
//    @BindView(R.id.tvObuEndDate)
    TextView tvObuEndDate;
//    @BindView(R.id.tvObuOperator)
    TextView tvObuOperator;
//    @BindView(R.id.tvObuStatus)
    TextView tvObuStatus;

    private String fileSystem = "";


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.view_obu_system_info, null);
//        ButterKnife.bind(view);
        initView();
        SetData();
        return view;
    }

    private void initView() {
        tvObuId = view.findViewById(R.id.tvObuId);
        tvObuNo = view.findViewById(R.id.tvObuNo);
        tvObuDefinition = view.findViewById(R.id.tvObuDefinition);
        tvObuType = view.findViewById(R.id.tvObuType);
        tvObuStartDate = view.findViewById(R.id.tvObuStartDate);
        tvObuEndDate = view.findViewById(R.id.tvObuEndDate);
        tvObuOperator = view.findViewById(R.id.tvObuOperator);
        tvObuStatus = view.findViewById(R.id.tvObuStatus);
    }

    private void SetData() {
        setContent(fileSystem);
    }

    public void setContent(String fileSystem) {
        if (!TextUtils.isEmpty(fileSystem)&&fileSystem.length()>62) {
            if (tvObuId != null&&tvObuNo!=null&&tvObuType!=null&&tvObuDefinition!=null
                    &&tvObuStartDate!=null&&tvObuEndDate!=null&&tvObuStatus!=null) {
                OBUSystemInfoMDL mdl = TopUpUtil.getObuSystemInfo(fileSystem.substring(8));
                if (mdl != null) {
                    tvObuId.setText(mdl.getOBUID());
                    tvObuNo.setText(mdl.getOBUNo());
                    tvObuType.setText(mdl.getType());
                    tvObuDefinition.setText(mdl.getOBUDefinition());
                    tvObuStartDate.setText(mdl.getStartDate());
                    tvObuEndDate.setText(mdl.getEndDate());
                    tvObuStatus.setText(mdl.getStatus());
                    tvObuOperator.setText(mdl.getOperator());
                }
            }else{
                this.fileSystem = fileSystem;
            }
        }
    }
}
